import { Logger } from "../engine/utils/Logger";

export class MJHeapCardInfo {

    // 摸牌顺时针，打牌逆时针
    public HeadUsedCount: number; //为堆头已经被抓取的数量，
    public TailUsedCount: number; //为堆尾已经被抓取的数量
    public AllCount: number; //为该牌墙最大牌数


    public static getChairByTouzi(touzi1: number, touzi2: number, seatNum: number, bankerChair: number) {
        let touziChair: number = (touzi1 + touzi2 - 1) % seatNum
        touziChair = (touziChair + (1 - bankerChair) + seatNum) % seatNum
        return touziChair;
    }


    public static mopai(headCardInfo: Array<MJHeapCardInfo>, mopaiChair: number, needNum: number) {
        let nowMochair: number = mopaiChair;
        do {
            let headInfo: MJHeapCardInfo = headCardInfo[nowMochair];
            // Logger.log("mopai===", headCardInfo,nowMochair,needNum )
            let leftNum: number = headInfo.AllCount - headInfo.HeadUsedCount - headInfo.TailUsedCount
            if (leftNum > needNum) {
                if (nowMochair == mopaiChair) {
                    headInfo.TailUsedCount += needNum;
                } else {
                    headInfo.HeadUsedCount += needNum;
                }
                needNum = 0
            } else {
                if (nowMochair == mopaiChair) {
                    headInfo.TailUsedCount += leftNum;
                } else {
                    headInfo.HeadUsedCount += leftNum;
                }
                needNum -= leftNum;
                nowMochair = nowMochair - 1;
                if (nowMochair < 0) {
                    nowMochair = 3
                }
            }
        } while (needNum > 0)
    }

}